import  store from '@/store'
import router from '@/router'
import NProgress from "nprogress";
import "nprogress/nprogress.css";
// 路由前置导航守卫
router.beforeEach((to,from,next)=>{
  //每次切换页面时，调用进度条
  NProgress.start();
  if(to.matched.some(ele=>ele.meta.isLogin)){ //需要登录
      if(store.state.login.userinfo.token){
        next()
      }else{
          next('/login')
      }

  }else{
    next()
  }
})
router.afterEach(() => {
  // 在即将进入新的页面组件前，关闭掉进度条
  NProgress.done();
});